// import config from '@/config'
// import cookie from '@/utils/store/cookie.js'
export const baseUrl = 'https://sqsl.e0s.cn/prod-api'
// export const baseUrl = 'https://sqsl.dev.e0s.cn/dev-api'
// export const baseUrl = 'http://123.57.17.213:8677/prod-api'
const responseStatusCallback = response => {
	uni.showToast({
		title: response.data.msg,
		icon: 'none',
		duration: 2000
	})
}
// http://sqsl.e0s.cn/api
// http://123.54.1.133:8677/prod-api
const service = (url, payload = {}, method = 'GET') => {
	const token = uni.getStorageSync('token') || ''
	let header = {}
	if (token && url != '/au/weiXinMp/callback' && url != '/business/userAsk/add') header['Authorization'] =
		'Bearer ' + token
	console.log('url', );
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method,
			data: payload,
			header,
			success: res => {
				// console.info('请求数据:' + JSON.stringify(res))
				// console.info(res)
				if (res.statusCode == 200) {
					if (res.data.code !== 200) {
						if (res.data.code === 401) {
							// uni.navigateTo({
							// 	url: '/pages/logoin/logoin'
							// })
							// uni.removeStorageSync('selectUser')
							uni.removeStorageSync('token')
							uni.removeStorageSync('userInfo')
							// uni.$u.toast('登录过期，请重新进入')
							// #ifdef H5
							window.location.href = 'http://sqsl.e0s.cn'
							// #endif
							// #ifdef MP-ALIPAY
							uni.switchTab({
								url: '/pages/index/index'
							})
							// #endif
							return
						}
						responseStatusCallback(res)
						reject(res)
					} else {
						resolve(res.data)
					}

				} else {
					responseStatusCallback(res)
					reject(res)
				}

			},
			fail: res => {
				responseStatusCallback(res)
				reject(res)
			}
		})
	})

}

export default service